/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cl.tienda.control;

import cl.tienda.modelo.Producto;
import cl.tienda.modelo.Usuario;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author 19029157-k
 */
public class ServletCConProd extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //Para mostrar la pagina Web
 Vector<Producto> productos = (Vector<Producto>) request.getSession().getAttribute("productos");
//Obtengo todos los datos de la sesion de usuario
        

        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet ServletCAgrCarrito1</title>");
            out.println("</head>");
            out.println("<body style='background:#F7DD75'>");

            out.println("<Center><table style='background:#FB1717' border='1' width='1000' cellspacing='0' cellpadding='1'>   ");
            out.println("<thead>");
            out.println("   <tr>");
            out.println(" <th width='100' height='100'><Center><img src='carrito.jpg' width='100' height='100' alt=''></Center></th>");
            out.println("   <th style='color:#FFFFFF'><h1>  Carrito de Compras con Vectores & Sesiones</h1></th>");
            out.println("</tr>");
            out.println("</table></center><br>");
            out.println("<center><h3><a href='ServletCConProd' style='color:#9E13A3'>Consultar Productos</a>|<a href='ServletCAgrCarrito1.view' style='color:#9E13A3'>Agregar al Carrito</a>|<a href='img/login.html' style='color:#9E13A3'>Salir</a></h3></center><br>");

            out.println("  <Center><table  border='1' bordercolor='#F7DD75' width='1000' cellspacing='0' cellpadding='1' >  ");
            out.println("<thead>");
            out.println("<tr style='background:#F78615'>");
            out.println(" <th align='left' style='color:#FFFFFF'>Nombre</th>");
            out.println("<th align='right' style='color:#FFFFFF'>Stock</th>");
            out.println("<th align='right' style='color:#FFFFFF'>Precio</th>");

            out.println("</tr>");
            out.println("</thead>");
            out.println("<tbody>");

            for (int i = 0; i < productos.size(); i++) {
                if (i % 2 == 0) {
                    out.println("<tr bgcolor=\"#FFFFFF\">");
                    out.println("<td>" + productos.get(i).getNombreProducto() + "</td>");
                    out.println("<td align=\"right\" valign=\"top\">" + productos.get(i).getStock() + "</td>");
                    out.println("<td align=\"right\" valign=\"top\">" + productos.get(i).getPrecio() + "</td>");
                    out.println("</tr>");
                } else {
                    out.println("<tr>");
                    out.println("<td>" + productos.get(i).getNombreProducto() + "</td>");
                    out.println("<td align=\"right\" valign=\"top\">" + productos.get(i).getStock() + "</td>");
                    out.println("<td align=\"right\" valign=\"top\">" + productos.get(i).getPrecio() + "</td>");
                    out.println("</tr>");

                }

            }
          
   
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
   
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
